package ar.unc.famaf.pln.giveselector.classifier;

import java.util.Comparator;

import ar.unc.famaf.pln.giveselector.context.Utterance;

/**
 * Compares Utterance objects by their grade.
 * The grade for an Utterance object is calculated
 * by a classifier object which must implement 
 * the IClassifier interface.
 *
 * @author David Racca ( david.racca@gmail.com )
 *
 */
public class UtteranceComparator implements Comparator<Utterance> {

	private IClassifier classifier;


	/**
	 * Creates an UtteranceComparator that will base its
	 * comparing criterion on the given classifier
	 * grade computation.
	 */
	public UtteranceComparator(IClassifier classifier)
	{
		this.classifier = classifier;
	}


	/**
	 * Compares the given Utterance objects by comparing
	 * their grades.
	 */
	public int compare(Utterance u1, Utterance u2)
	{
		float s1 = classifier.getScore(u1);
		float s2 = classifier.getScore(u2);
		return (s1 > s2) ? 1 : ((s1 == s2) ? 0 : -1);
	}

}
